<template>
  <div class="kpi-item">
    <div class="kpi-content">
      <div class="kpi-left">
        <h3 class="kpi-name">{{ item.title }}</h3>
        <div class="kpi-percentage">
          {{ ((item.completeValue/(Number(item.completeValue) +Number(item.remainingValue)))*100 ).toFixed(1) }}%</div>
      </div>
    </div>

    <div class="progress-container">
      <div class="progress-track">
        <div
            class="progress-bar "
            :class="[`progress-completed`]"
            :style="{ width: Math.min(((item.completeValue/(Number(item.completeValue) +Number(item.remainingValue)))*100 ).toFixed(1), 100) + '%' }"
        ></div>
        <div class="kpi-values">{{ item.completeValue }}/{{ item.remainingValue }}</div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'KpiItem',
  props: {
    item: {
      type: Object,
      required: true
    }
  }
}
</script>

<style scoped>
.kpi-item {
}


.kpi-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.kpi-left {
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: space-between;
}

.kpi-name {
  color: #ccc;
  font-size: 14px;
  font-weight: 400;
  margin-bottom: 4px;
  line-height: 1.4;
}

.kpi-percentage {
  padding-right: 60px;
  color: #ccc;
  font-size: 14px;
  font-weight: 600;
}

.kpi-right {
  text-align: right;
}

.kpi-values {
  width: 50px;
  text-align: center;
  position: absolute;
  top: -5px;
  right: -55px;
  font-size: 12px;
  font-weight: 500;
}

.progress-container {
  width: 100%;
}

.progress-track {
  width: 90%;
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
  position: relative;
}

.progress-bar {
  height: 100%;
  border-radius: 3px;
  transition: width 0.6s ease-in-out;
}

.progress-completed {
  background: linear-gradient(to right, #01a3da, #37e794);
  box-shadow: 0 0 10px rgba(0, 212, 170, 0.3);
}

.progress-pending {
  background: linear-gradient(90deg, #4299e1, #3182ce);
  box-shadow: 0 0 10px rgba(66, 153, 225, 0.3);
}

@media (max-width: 768px) {
  .kpi-content {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .kpi-right {
    text-align: left;
  }

  .kpi-name {
    font-size: 13px;
  }

  .kpi-percentage {
    font-size: 20px;
  }
}
</style>